<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>学生信息管理</title>
<script type="text/javascript">
	var url;
	//打开新增患者对话框
	function openPatientAddDialog() {
		//在勾选情况下点击新增要先清除数据
		resetValue();
		$("#dlg").dialog("open").dialog("setTitle", "添加学生信息");
		url = "${pageContext.request.contextPath}/student/save.do";//为url赋值
	}
	//重置对话框内数据
	function resetValue() {
		$("#name").val("");
		$("#username").val("");
		$("#password").val("");
		$("#idcard").val("");
		$("#email").val("");
		$("#score").val("");
	}
	//关闭对话框
	function closePatientDialog() {
		$("#dlg").dialog("close");
		resetValue();
	}
	//提交新增患者数据
	function savePatient() {

		$("#fm").form("submit", {
			url : url,
			onSubmit : function() {
				return $(this).form("validate");
			},
			success : function(result) {
				if (result.errorMsg) {
					$.messager.alert("系统提示", result.errorMsg);
					return;
				} else {
					$.messager.alert("系统提示", "保存成功");
					resetValue();
					$("#dlg").dialog("close");
					$("#dg").datagrid("reload");
				}
			}
		});
	}
	//删除选中的患者数据
	function deletePatient() {
		//获得选中数据对象
		var selectedRows = $("#dg").datagrid('getSelections');
		if (selectedRows.length == 0) {
			$.messager.alert("系统提示", "请选择要删除的数据！");
			return;
		}
		var strIds = [];//要删除的序号组合
		for (var i = 0; i < selectedRows.length; i++) {
			strIds.push(selectedRows[i].id);
		}
		var ids = strIds.join(",");
		$.messager.confirm("系统提示", "您确认要删掉这<font color=red>"
				+ selectedRows.length + "</font>条数据吗？", function(r) {
			if (r) {
				//ajax提交 delIds
				$.post("${pageContext.request.contextPath}/student/delete.do",
						{
							ids : ids
						}, function(result) {
							if (result.success) {
								$.messager.alert("系统提示",
										"您已成功删除<font color=red>"
												+ result.delNums
												+ "</font>条数据！");
								$("#dg").datagrid("reload");
							} else {
								$.messager.alert('系统提示', result.errorMsg);
							}
						}, "json");
			}
		});
	}
	//修改患者资料
	function openPatientModifyDialog() {
		var selectedRows = $("#dg").datagrid('getSelections');
		if (selectedRows.length != 1) {
			$.messager.alert("系统提示", "请选择一条要编辑的数据！");
			return;
		}
		var row = selectedRows[0];
		url = "${pageContext.request.contextPath}/student/save.do?id=" + row.id;
		$("#dlg").dialog("open").dialog("setTitle", "编辑资料");
		$("#name").val(row.name);
		$("#username").val(row.username);
		$("#password").val(row.password);
		$("#idcard").val(row.idcard);
		$("#email").val(row.email);
		$("#score").val(row.score);
		$("#subject").combobox("setValue", row.subject);
		$("#power").combobox("setValue", row.power);
	}
	//查询符合条件的用户
	function searchPatient() {
		$('#dg').datagrid('load', {
			sidcard : $('#sidcard').val(),
			sname : $('#sname').val(),
		});
	}
	//倒出excel数据
	function exportPatient() {
		$('#export').form("submit", {
			url : "${pageContext.request.contextPath}/student/excel.do"
		})
	}
	//倒入excel数据
	function importPatient() {
		$("#dlg1").dialog("open").dialog("setTitle", "导入数据");
		url = "${pageContext.request.contextPath}/student/importexcel.do.do";//为url赋值
	}
</script>
<link rel="stylesheet" type="text/css"
	href="${pageContext.request.contextPath}/jquery-easyui-1.3.3/themes/default/easyui.css">
<link rel="stylesheet" type="text/css"
	href="${pageContext.request.contextPath}/jquery-easyui-1.3.3/themes/icon.css">
<script type="text/javascript"
	src="${pageContext.request.contextPath}/jquery-easyui-1.3.3/jquery.min.js"></script>
<script type="text/javascript"
	src="${pageContext.request.contextPath}/jquery-easyui-1.3.3/jquery.easyui.min.js"></script>
<script type="text/javascript"
	src="${pageContext.request.contextPath}/jquery-easyui-1.3.3/locale/easyui-lang-zh_CN.js"></script>
</head>
<body style="margin: 5px">
	<table id="dg" title="学生信息" class="easyui-datagrid" fitColumns="true"
		pagination="true" rownumbers="true"
		url="${pageContext.request.contextPath}/student/list.do" fit="true"
		toolbar="#tb">
		<thead>
			<tr>
				<th field="cb" checkbox="true">编号</th>
				<th field="id" width="30" align="center" hidden="true">id</th>
				<th field="name" width="15" align="center">名字</th>
				<th field="username" width="20" align="center">账号</th>
				<th field="password" width="20" align="center">密码</th>
				<th field="idcard" width="30" align="center">准考证</th>
				<th field="subject" width="15" align="center">科目</th>
				<th field="score" width="15" align="center">分数</th>
				<th field="email" width="30" align="center">邮箱</th>
				<th field="power" width="15" align="center">状态</th>
			</tr>
		</thead>
	</table>
	<div id="tb">
		<div>
			<a href="javascript:openPatientAddDialog()" class="easyui-linkbutton"
				iconCls="icon-add" plain="true">添加</a> <a
				href="javascript:openPatientModifyDialog()"
				class="easyui-linkbutton" iconCls="icon-edit" plain="true">修改</a> <a
				href="javascript:deletePatient()" class="easyui-linkbutton"
				iconCls="icon-remove" plain="true">删除</a> <a
				href="javascript:exportPatient()" class="easyui-linkbutton"
				iconCls="icon-export" plain="true">导出Execl</a> <a
				href="javascript:importPatient()" class="easyui-linkbutton"
				iconCls="icon-export" plain="true">导入Execl</a>
			<%-- <form action="${pageContext.request.contextPath}/student/importexcel.do" method="post" enctype="multipart/form-data" target="main" id="ex">
				<input type="file" name="filename">
				<input type="submit" value="导入学生信息" id="sub">
			</form> --%>
		</div>
		<div>
			<form id="export" method="post">
				&nbsp;姓名：&nbsp;<input type="text" name="sname" id="sname" size="10" />
				&nbsp;准考证：&nbsp;<input type="text" name="sidcard" id="sidcard"
					size="10" /> <a href="javascript:searchPatient()"
					class="easyui-linkbutton" iconCls="icon-search" plain="true">搜索</a>
			</form>
		</div>
	</div>

	<div id="dlg" class="easyui-dialog"
		style="width: 570px; height: 340px; padding: 10px 20px" closed="true"
		buttons="#dlg-buttons">
		<form id="fm" method="post" enctype="multipart/form-data">
			<table cellspacing="5px;">
				<tr>
					<td>名字：</td>
					<td><input type="text" name="name" id="name"
						class="easyui-validatebox" /></td>
					<td>账号：</td>
					<td><input type="text" name="username" id="username"
						class="easyui-validatebox" /></td>
				</tr>
				<tr>
					<td>密码：</td>
					<td><input type="text" name="password" id="password"
						class="easyui-validatebox" /></td>
					<td>准考证：</td>
					<td><input type="text" name="idcard" id="idcard"
						class="easyui-validatebox" /></td>
				</tr>
				<tr>
					<td>科目：</td>
					<td><select name="subject" id="subject"
						class="easyui-combobox" style="width: 175px;">
							<option value="1" selected="selected">理科</option>
							<option value="0">文科</option>
					</select></td>
					<td>分数：</td>
					<td><input type="text" name="score" id="score"
						class="easyui-validatebox" /></td>
				</tr>
				<tr>
					<td>邮箱：</td>
					<td><input type="text" name="email" id="email"
						class="easyui-validatebox" /></td>
					<td>状态：</td>
					<td><select name="power" id="power" class="easyui-combobox"
						style="width: 175px;">
							<option value="1" selected="selected">可用</option>
							<option value="0">封锁</option>
					</select></td>
				</tr>
			</table>
		</form>
	</div>


	<div id="dlg1" class="easyui-dialog"
		style="width: 570px; height: 340px; padding: 10px 20px" closed="true"
		buttons="#dlg-buttons">
		<form id="fm" method="post" enctype="multipart/form-data">
			<table cellspacing="5px;">
				<tr>
					<td>文件：</td>
					<td><input type="file" name="filename"></td>
				</tr>
			</table>
		</form>
	</div>

	<div id="dlg-buttons">
		<a href="javascript:savePatient()" class="easyui-linkbutton"
			iconCls="icon-ok">保存</a> <a href="javascript:closePatientDialog()"
			class="easyui-linkbutton" iconCls="icon-cancel">关闭</a>
	</div>
</body>
</html>